package com.gu.controller;

import com.gu.VO.ServerResponse;
import com.gu.VO.UserVO;
import com.gu.entity.UserDO;
import com.gu.service.ApartmentInfoService;
import com.gu.service.UserService;
import com.gu.utils.UserDO2VO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @ProjectName: apartment-management-center
 * @Package: com.gu.controller
 * @ClassName: SystemController
 * @Author: gusongliao
 * @Description: 系统控制器
 * @createDate 2021/02/09 21:21
 */

@Controller
@RequestMapping("/system")
public class SystemController {

    @Autowired
    private ApartmentInfoService apartmentInfoService;

    @Autowired
    private UserService userService;

    @RequestMapping("/home")
    public String home(HttpServletRequest request){
        request.getServletContext().setAttribute("apartmentInfo",apartmentInfoService.getById(1).getApartmentinfo());
        return "index";
    }

    @RequestMapping("/jump")
    public String path(String path){
        return path;
    }


    @RequestMapping("/jumpRedirect")
    public String jumpRedirect(String path){
        return "redirect:" + path;
    }

    @RequestMapping("/refreshPage")
    public void refreshPage(HttpServletRequest request, Integer id){
        UserDO user = userService.getUserById(id);
        UserVO userVO = UserDO2VO.userDO2UserVO(user);
        request.getServletContext().setAttribute("user",userVO);
    }

    @RequestMapping("/getUserById")
    @ResponseBody
    public UserDO getUserById(Integer id){
        return userService.getUserById(id);
    }


}
